home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
music4c.sit
/
Music4C Folder
/
Sources Folder
/
Music4CFile.c
< prev
next >
Wrap
Text File
|
1990-09-09
|
23KB
|
859 lines
/*
* ⌐ Graeme Gerrard 1990
* Faculty of Music, University of Melbourne
* Parkville Victoria 3052 Australia.
*
* ARPANET: grae@murdu.ucs.unimelb.edu.au
* telephone: (613) 344 4127, Fax: (613) 344 5346
*/
#include "Music4C.h"
#include "Music4C_Prototype.h"
/*#include <unix.h>*/
Boolean OpenSFWrite(void);
Boolean SetSFDir(Str255, long *);
Boolean GetSFDir(Str255 *);
Boolean CloseSF(void);
Boolean FullFileName(StringPtr, StringPtr, short, long);
Boolean updateSFResFile(void);
void Finish(void);
Boolean SFVolDir(short, short *, long *);
Boolean doSD2Resources(void);
OSErr FullToFolder(StringPtr, short *, long *);
void FixUp(void);
extern void SaveMusic4C_Prefs(void);
extern void ClosePass3Input(void);
Boolean ScoreFileIsOpen;
Boolean SoundFileIsOpen;
Boolean ReportFileIsOpen;
#define SAMPLE_SIZE_RES 1000
#define SAMPLE_RATE_RES 1001
#define SAMPLE_CHANNELS_RES 1002
SFReply SoundFileReply;
SFReply ScoreFileReply;
Str255 SoundFileName;
ioParam myIOParmBlk;
int sfResFileRefNum;
WDPBRec myWDParamBlk;
FileParam fPB;
long SampleRate;
extern OSErr theErr;
Str255 theMess1, theMess2;
int rfilevRefNum;
Boolean
OpenSFWrite()
{
SFTypeList types;
Point where;
int AppResFile;
extern long StartUpDirID;
extern long SoundFileDirID;
extern int SFoutputType;
extern int SFSaveVRef;
extern int SFvRefNum;
extern Str255 SFDirectoryName;
int c;
short volume;
long folder;
short wd;
extern int nchnls; /* number of output channels */
if ( SFDirectoryName[0] != NIL ) {
if ( !SetSFDir(SFDirectoryName, &SoundFileDirID) ) {
CurDirStore = StartUpDirID;
return(FALSE);
}
}
PstringCopy((char *)SoundFileName, (char *)ScoreFileReply.fName);
PtoCstr((char *)SoundFileName);
c = strcspn((char *)SoundFileName,".");
switch(SFoutputType) {
case INT16:
strcpy((char *)SoundFileName+c, ".INT16");
break;
case AIFF:
strcpy((char *)SoundFileName+c, ".AIF");
break;
case SD:
strcpy((char *)SoundFileName+c, ".SD");
break;
case FLOAT:
strcpy((char *)SoundFileName+c, ".FLOAT");
break;
}
CtoPstr((char *)SoundFileName);
SetPt(&where, 100, 100);
SFPutFile(where, "\pSound File name:", &SoundFileName, NIL, &SoundFileReply);
if(!SoundFileReply.good)
return(FALSE);
GetSFDir(&SFDirectoryName);
/* we now have the directory where the sound file is to be created,
save it in the Music4C_Prefs file */
SaveMusic4C_Prefs();
SetSFDir(SFDirectoryName, &SoundFileDirID);
PstringCopy((char *)SoundFileName, (char *)SoundFileReply.fName);
myIOParmBlk.ioNamePtr = (StringPtr)SoundFileName;
myIOParmBlk.ioVRefNum = SoundFileReply.vRefNum;
myIOParmBlk.ioVersNum = SoundFileReply.version;
if ( (theErr = PBCreate(&myIOParmBlk, FALSE)) != noErr ) {
if ( theErr == dupFNErr ) { /* set logical EOF's to zero */
myIOParmBlk.ioPermssn = fsWrPerm;
myIOParmBlk.ioMisc = (Ptr)NIL;
theErr = PBOpen(&myIOParmBlk, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError opening sound file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
myIOParmBlk.ioMisc = (Ptr)1;
theErr = PBSetEOF(&myIOParmBlk, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError setting EOF for sound file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
theErr = PBClose(&myIOParmBlk, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError while setting EOF for sound file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
/* do resource fork */
myIOParmBlk.ioMisc = (Ptr)NIL;
theErr = PBOpenRF(&myIOParmBlk, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError opening sound file resource fork:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
theErr = PBSetEOF(&myIOParmBlk, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError setting EOF for sound file resource fork:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
/* close resource fork */
theErr = PBClose(&myIOParmBlk, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError while setting EOF for sound file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
}
else { /* error other than dupFNerr */
PstringCopy((char *)theMess1, "\pOpenSFWrite Error creating file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
}
else { /* new files only */
}
fPB.ioCompletion = (ProcPtr)NIL;
fPB.ioNamePtr = myIOParmBlk.ioNamePtr;
fPB.ioVRefNum = myIOParmBlk.ioVRefNum;
fPB.ioFVersNum = myIOParmBlk.ioVersNum;
fPB.ioFDirIndex = NIL;
theErr = PBGetFInfo(&fPB, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pOpenSFWrite Error getting PBGetFInfo while opening file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
/* set creator */
fPB.ioFlFndrInfo.fdCreator = 'MU4C';
switch(SFoutputType) {
case INT16:
fPB.ioFlFndrInfo.fdType = 'IL16';
break;
case AIFF:
fPB.ioFlFndrInfo.fdType = 'AIFF';
break;
case SD:
fPB.ioFlFndrInfo.fdType = 'SFIL';
fPB.ioFlFndrInfo.fdCreator = 'XFER';
break;
case FLOAT:
fPB.ioFlFndrInfo.fdType = 'TEXT';
break;
}
fPB.ioFlFndrInfo.fdFlags = NIL;
theErr = PBSetFInfo(&fPB, FALSE);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pOpenSFWrite Error setting PBGetFInfo while opening file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
PBFlushVol(&fPB, FALSE);
/* now open it */
myIOParmBlk.ioPermssn = fsWrPerm;
myIOParmBlk.ioMisc = (Ptr)NIL;
if ( (theErr = PBOpen(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pOpenSFWrite Error opening file:");
OSError(theMess1, SoundFileName, theErr);
CurDirStore = StartUpDirID;
return(FALSE);
}
return(TRUE);
}
Boolean CloseSF()
{
extern int nchnls; /* number of output channels */
if ( (theErr = PBClose(&myIOParmBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError closing Sound File:");
OSError(theMess1, SoundFileName, theErr);
return(FALSE);
}
/* if SD2 file fix file type */
if ( SFoutputType == SD && nchnls > 1 ) {
fPB.ioFlFndrInfo.fdType = 'Sd2f';
fPB.ioFlFndrInfo.fdCreator = 'Sd2a';
fPB.ioFlFndrInfo.fdFlags = NIL;
theErr = PBSetFInfo(&fPB, FALSE);
}
fPB.ioCompletion = (ProcPtr)NIL;
fPB.ioNamePtr = myIOParmBlk.ioNamePtr;
fPB.ioVRefNum = myIOParmBlk.ioVRefNum;
fPB.ioFVersNum = myIOParmBlk.ioVersNum;
fPB.ioFDirIndex = NIL;
if ( (theErr = PBFlushVol(&fPB, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pError returned from PBFlushVol for sample file's volume:");
OSError(theMess1, NIL, theErr);
return(FALSE);
}
return(TRUE);
}
Boolean SetSFDir(DirName, theDirID)
Str255 DirName;
long *theDirID;
{
extern int SFSaveVRef;
extern int ReportFileRefNum;
Str255 aString;
PstringCopy((char *)aString, (char *)DirName);
myWDParamBlk.ioNamePtr = (StringPtr)aString;
myWDParamBlk.ioCompletion = NIL;
myWDParamBlk.ioVRefNum = 0;
myWDParamBlk.ioWDDirID = NIL;
if ( (theErr = PBHSetVol(&myWDParamBlk, FALSE)) != noErr ) {
}
PBHGetVol(&myWDParamBlk, FALSE);
*theDirID = myWDParamBlk.ioWDDirID;
CurDirStore = *theDirID;
SFSaveVRef = myWDParamBlk.ioVRefNum;
SFSaveDisk = -1 * SFSaveVRef;
return(TRUE);
}
Boolean GetSFDir(DirName)
Str255 *DirName;
{
Str255 myStr;
WDPBRec myWDParamBlk;
DirInfo myCatInfoBlk;
myCatInfoBlk.ioCompletion = NIL;
myCatInfoBlk.ioVRefNum = -SFSaveDisk;
myCatInfoBlk.ioDrDirID = CurDirStore;
myCatInfoBlk.ioFDirIndex = -1;
myCatInfoBlk.ioNamePtr = (StringPtr)myStr;
if ( (theErr = PBGetCatInfo(&myCatInfoBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pPBGetCatInfo Error:");
OSError(theMess1, myCatInfoBlk.ioNamePtr, theErr);
return(FALSE);
}
PstringCopy((char *)DirName, (char *)myStr);
PstringCat((char *)DirName, "\p:");
while (myCatInfoBlk.ioDrDirID != 2 ) {
myCatInfoBlk.ioDrDirID = myCatInfoBlk.ioDrParID;
if ( (theErr = PBGetCatInfo(&myCatInfoBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pPBGetCatInfo error:");
OSError(theMess1, myCatInfoBlk.ioNamePtr, theErr);
return(FALSE);
}
PstringCat((char *)myStr, "\p:");
PstringCat((char *)myStr, (char *)DirName);
PstringCopy((char *)DirName, (char *)myStr);
}
CurDirStore = myCatInfoBlk.ioDrDirID;
return(TRUE);
}
Boolean OpenScoreFile()
{
SFTypeList types;
Point where;
extern Str255 ScoreDirectoryName;
extern Str255 sfile;
Str255 tail;
short volume;
long dirID;
extern Str255 StartDirName;
extern int scoreRefNum;
SetPt(&where, 100, 100);
SFGetFile(where, NIL, NIL, -1, NIL, NIL, &ScoreFileReply);
if(!ScoreFileReply.good)
return(FALSE);
/* get the name of the score folder name */
StartDirName[0] = 0;
tail[0] = 0;
volume = 0;
dirID = NIL;
FullFileName(StartDirName, tail, volume, dirID);
scoreRefNum = 0;
PstringCopy((char *)sfile, (char *)ScoreFileReply.fName);
theErr = FSOpen(sfile, ScoreFileReply.vRefNum, &scoreRefNum);
if (theErr != noErr) {
PstringCopy((char *)theMess1, "\pError opening score file:");
OSError(theMess1, ScoreFileReply.fName, theErr);
return(FALSE);
}
return(TRUE);
}
void CleanUp(errFlag)
Boolean errFlag;
{
extern int rfilevRefNum;
extern Str255 rfile;
extern Boolean CreateSoundFile;
extern Str255 p2tmp;
int i;
if ( ScoreFileIsOpen ) {
theErr = FSClose(scoreRefNum);
ScoreFileIsOpen = FALSE;
}
if ( ReportFileIsOpen ) {
theErr = FSClose(ReportFileRefNum);
if (errFlag)
theErr = FSDelete(rfile, rfilevRefNum);
ReportFileIsOpen = FALSE;
}
if ( SoundFileIsOpen ) {
if (!errFlag) /* don't update resource if we cancelled out */
updateSFResFile();
theErr = PBClose(&myIOParmBlk, FALSE);
SoundFileIsOpen = FALSE;
if (errFlag)
theErr = PBDelete(&myIOParmBlk, FALSE);
}
FixUp(); /* resets startup directory */
}
typedef struct {
int nstrings;
unsigned char theStrings[256];
} ResDatum;
Boolean updateSFResFile()
{
ResDatum **newSfRes;
unsigned char *strptr;
Str255 myString;
StringHandle myStringHandle1, myStringHandle2, myStringHandle3;
long SampleRate;
extern int AppResFile;
extern int nchnls; /* number of output channels */
extern double srate; /* sampling rate */
extern float MaxSample;
extern float MinSample;
extern int SFoutputType;
int i;
SampleRate = (long)srate;
CurDirStore = SoundFileDirID;
myWDParamBlk.ioCompletion = NIL;
myWDParamBlk.ioNamePtr = NIL;
if ( (theErr = PBOpenWD(&myWDParamBlk, FALSE)) != noErr ) {
PstringCopy((char *)theMess1, "\pUpdateResFile - PBOpenWD error:");
OSError(theMess1, myWDParamBlk.ioNamePtr, theErr);
return(FALSE);
}
/* open the resource fork */
CreateResFile(SoundFileName);
if ( ( theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pupdateSFResFile CreateResFile error:");
OSError(theMess1, SoundFileName, theErr);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
/* return(FALSE);*/
}
sfResFileRefNum = OpenResFile(SoundFileName);
if ( ( theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pupdateSFResFile: OpenResFile error:");
OSError(theMess1, SoundFileName, theErr);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
return(FALSE);
}
newSfRes = (ResDatum **) NewHandle((long)sizeof(ResDatum));
HLock(newSfRes);
(**newSfRes).nstrings = 5;
strptr = &((*newSfRes)->theStrings[0]);
switch(SFoutputType) {
case INT16:
PstringCopy((char *)strptr, "\pINT16");
strptr += (*strptr) + 1;
break;
case AIFF:
PstringCopy((char *)strptr, "\pAIFF");
strptr += (*strptr) + 1;
break;
case SD:
if (nchnls > 1 ) {
PstringCopy((char *)strptr, "\pSD2");
doSD2Resources();
}
else
PstringCopy((char *)strptr, "\pSD1");
strptr += (*strptr) + 1;
break;
case FLOAT:
PstringCopy((char *)strptr, "\pFLOAT");
strptr += (*strptr) + 1;
break;
}
NumToString((long)nchnls, &myString);
PstringCopy((char *)strptr, (char *)myString);
strptr += (*strptr) + 1;
NumToString(SampleRate, &myString);
PstringCopy((char *)strptr, (char *)myString);
strptr += (*strptr) + 1;
sprintf((char *)myString, "%lf", (double)MaxSample);
CtoPstr((char *)myString);
PstringCopy((char *)strptr, (char *)myString);
strptr += (*strptr) + 1;
sprintf((char *)myString, "%lf", (double)MinSample);
CtoPstr((char *)myString);
PstringCopy((char *)strptr, (char *)myString);
AddResource(newSfRes, 'STR#', 1000, "\pSF params");
if ((theErr = ResError()) != noErr) {
PstringCopy((char *)theMess1, "\pAddResource error in function: updateSFResFile():");
OSError(theMess1, NIL, theErr);
HUnlock(newSfRes);
DisposHandle(newSfRes);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
UseResFile(AppResFile);
CurDirStore = StartUpDirID;
return(FALSE);
}
ChangedResource(newSfRes);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pChangedResource error in function: updateSFResFile():");
OSError(theMess1, SoundFileName, theErr);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
return(FALSE);
}
WriteResource(newSfRes);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pWriteResource error in function: updateSFResFile():");
OSError(theMess1, SoundFileName, theErr);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
return(FALSE);
}
CloseResFile(sfResFileRefNum);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pCloseResFile error in function: updateSFResFile():");
OSError(theMess1, SoundFileName, theErr);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
return(FALSE);
}
HUnlock(newSfRes);
DisposHandle(newSfRes);
UseResFile(AppResFile);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pUseResFile error in function: updateSFResFile():");
OSError(theMess1, SoundFileName, theErr);
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
return(FALSE);
}
CloseSF();
theErr = PBCloseWD(&myWDParamBlk, FALSE);
CurDirStore = StartUpDirID;
return(TRUE);
}
/*-------------------------------------------------------------------------------*/
Boolean SFVolDir(short wd, short *volume, long *folder)
{
WDPBRec pb;
unsigned char name[72];
pb.ioNamePtr = (StringPtr)name;
pb.ioVRefNum = wd;
pb.ioWDIndex = 0;
pb.ioWDProcID = 0;
pb.ioWDVRefNum = 0;
PBGetWDInfo(&pb, false);
if (pb.ioResult) return pb.ioResult;
*volume = pb.ioWDVRefNum;
*folder = pb.ioWDDirID;
return (noErr);
}
/*
FullFileName should be passed an empty string in tail if you just want
the name of a folder.
*/
Boolean FullFileName(StringPtr outname, StringPtr tail, short volume, long dirID)
{
StringHandle name;
Str255 text, volname;
HVolumeParam hvp;
CInfoPBRec di;
long size;
short err;
/* extract the volume name */
hvp.ioNamePtr = volname;
hvp.ioVRefNum = volume;
hvp.ioVolIndex = 0;
PBHGetVInfo((HParmBlkPtr)&hvp, false);
if (hvp.ioVSigWord == 0xd2d7) {
outname[0] = 0;
return (noErr);
}
/* create and initialize the name handle */
if (tail) {
if (err = PtrToHand(tail + 1, &name, tail[0]))
return (err);
size = tail[0];
}
else {
if ((name = (StringHandle)NewHandle(NIL)) == 0)
return (MemError());
size = 0;
}
/* now start extracting the dirs and prepending them to
* the handle
*/
for ( ; dirID != 2; dirID = di.dirInfo.ioDrParID) {
text[0] = 0;
di.dirInfo.ioNamePtr = text;
di.dirInfo.ioVRefNum = volume;
di.dirInfo.ioFDirIndex = -1;
di.dirInfo.ioDrDirID = dirID;
PBGetCatInfo(&di, false);
text[++text[0]] = ':';
SetHandleSize(name, size += text[0]);
BlockMove((Ptr)*name, (Ptr)(*name) + text[0], size - text[0]);
BlockMove((Ptr)text + 1, (Ptr)*name, text[0]);
}
/* prepend the volume name onto the handle */
volname[++volname[0]] = ':';
SetHandleSize(name, size += volname[0]);
BlockMove((Ptr)*name, (Ptr)(*name) + volname[0], size - volname[0]);
BlockMove((Ptr)volname + 1, (Ptr)*name, volname[0]);
/* copy and delete the handle */
if (size > 255) {
DisposHandle(name);
SysBeep(12);
outname[0] = 0;
return err;
}
outname[0] = size;
BlockMove((Ptr)*name, (Ptr)outname + 1, size);
DisposHandle(name);
return (noErr);
}
/* And on the theory that you might want to convert the name back some day,
here's a routine I use for that. Notice that it will actually create the
directory if it doesn't exist now. If this isn't what you want, throw
away the error recovery code.
*/
OSErr FullToFolder(StringPtr name, short *volume, long *folder)
{
CInfoPBRec dirInfo;
HVolumeParam hvp;
short i;
dirInfo.dirInfo.ioNamePtr = name;
dirInfo.dirInfo.ioDrDirID = 0;
dirInfo.dirInfo.ioVRefNum = 0;
dirInfo.dirInfo.ioFDirIndex = 0;
if (PBGetCatInfo (&dirInfo, 0) == noErr) {
if (dirInfo.dirInfo.ioFlAttrib & 0x10) {
*folder = dirInfo.dirInfo.ioDrDirID;
hvp.ioNamePtr = name;
for (i = 0; i < name[0]; i++)
if (name[i+1] == ':') {
name[0] = i + 1; break;
}
hvp.ioVolIndex = -1;
hvp.ioVRefNum = 0;
PBHGetVInfo ((HParmBlkPtr)&hvp, 0);
*volume = hvp.ioVRefNum;
}
else {
*volume = 0;
*folder = 0;
return (-1);
}
}
else if (dirInfo.dirInfo.ioResult == fnfErr || dirInfo.dirInfo.ioResult == dirNFErr) {
dirInfo.dirInfo.ioNamePtr = (StringPtr)name;
dirInfo.dirInfo.ioDrDirID = 0;
dirInfo.dirInfo.ioVRefNum = 0;
if (PBDirCreate((HParmBlkPtr)&dirInfo, false) == noErr) {
*volume = dirInfo.dirInfo.ioVRefNum;
*folder = dirInfo.dirInfo.ioDrDirID;
}
else {
*volume = 0;
*folder = 0;
return (dirInfo.dirInfo.ioResult);
}
}
else {
*volume = 0;
*folder = 0;
return (dirInfo.dirInfo.ioResult);
}
return (noErr);
}
Boolean OpenReportFile(ReportFileRefNum)
int *ReportFileRefNum;
{
SFTypeList types;
Point where;
extern Str255 sfile;
extern Str255 rfile;
SFReply ReportFileReply;
extern int rfilevRefNum;
PstringCopy((char *)rfile, (char *)sfile);
PstringCat((char *)rfile, "\pReport");
SetPt(&where, 100, 100);
types[0] = 'TEXT';
SFPutFile(where, "\pReport File name:", &rfile, NIL, &ReportFileReply);
if(!ReportFileReply.good)
return(FALSE);
PstringCopy((char *)rfile, (char *)ReportFileReply.fName);
if ( (theErr = Create(rfile, ReportFileReply.vRefNum, 'MU4C', 'TEXT')) != noErr ) {
if ( theErr == dupFNErr ) {
rfilevRefNum = ReportFileReply.vRefNum;
theErr = FSDelete(rfile, rfilevRefNum);
if ( (theErr = Create(rfile, ReportFileReply.vRefNum, 'MU4C', 'TEXT')) != noErr ) {
PstringCopy((char *)theMess1, "\pError creating report file:");
OSError(theMess1, NIL, theErr);
FixUp();
Finish();
}
}
else {
PstringCopy((char *)theMess1, "\pError opening report file:");
OSError(theMess1, NIL, theErr);
FixUp();
Finish();
}
}
theErr = FSOpen(rfile, ReportFileReply.vRefNum, ReportFileRefNum);
if ( theErr != noErr ) {
PstringCopy((char *)theMess1, "\pError opening report file:");
OSError(theMess1, NIL, theErr);
FixUp();
Finish();
}
return(TRUE);
}
void FixUp()
{
if ( StartDirName[0] != NIL ) {
SetSFDir(StartDirName, &StartUpDirID);
}
}
void Finish()
{
InitCursor();
ExitToShell();
}
Boolean doSD2Resources()
{
register i;
StringHandle myStringHandle1, myStringHandle2, myStringHandle3;
Str255 myString;
myStringHandle1 = (StringHandle)NewHandle(sizeof(StringHandle));
i = sprintf((char *)myString, "%d", (int)nchnls);
CtoPstr((char *)myString);
SetString(myStringHandle1, myString);
HLock((Handle)myStringHandle1);
AddResource((Handle)myStringHandle1, 'STR ', SAMPLE_CHANNELS_RES, "\pchannels");
HUnlock((Handle)myStringHandle1);
ChangedResource((Handle)myStringHandle1);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pChangedResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle1);
DisposHandle((Handle)myStringHandle1);
return(FALSE);
}
WriteResource((Handle)myStringHandle1);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pWriteResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle1);
DisposHandle((Handle)myStringHandle1);
return(FALSE);
}
myStringHandle2 = (StringHandle)NewHandle(sizeof(StringHandle));
i = sprintf((char *)myString, "%ld", (long)SampleRate);
CtoPstr((char *)myString);
SetString(myStringHandle2, myString);
HLock((Handle)myStringHandle2);
AddResource((Handle)myStringHandle2, 'STR ', SAMPLE_RATE_RES, "\psample-rate");
HUnlock((Handle)myStringHandle2);
ChangedResource((Handle)myStringHandle2);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pChangedResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle2);
DisposHandle((Handle)myStringHandle2);
return(FALSE);
}
WriteResource((Handle)myStringHandle2);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pWriteResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle2);
DisposHandle((Handle)myStringHandle2);
return(FALSE);
}
myStringHandle3 = (StringHandle)NewHandle(sizeof(StringHandle));
SetString(myStringHandle3, "\p2");
HLock((Handle)myStringHandle3);
AddResource((Handle)myStringHandle3, 'STR ', SAMPLE_SIZE_RES, "\psample-size");
HUnlock((Handle)myStringHandle3);
if ((theErr = ResError()) != noErr) {
PstringCopy((char *)theMess1, "\pAddResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle3);
DisposHandle((Handle)myStringHandle3);
return(FALSE);
}
ChangedResource((Handle)myStringHandle3);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pChangedResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle3);
DisposHandle((Handle)myStringHandle3);
return(FALSE);
}
WriteResource((Handle)myStringHandle3);
if ( (theErr = ResError()) != noErr ) {
PstringCopy((char *)theMess1, "\pWriteResource error in updateNewSFResFile()");
OSError(theMess1, SoundFileName, theErr);
HUnlock((Handle)myStringHandle3);
DisposHandle((Handle)myStringHandle3);
return(FALSE);
}
HUnlock((Handle)myStringHandle3);
DisposHandle((Handle)myStringHandle1);
DisposHandle((Handle)myStringHandle2);
DisposHandle((Handle)myStringHandle3);
}